@extends('layouts.admin')

@section('css')

@endsection

@section('content')
    <section class="content" id="app">
        <div class="row">
            <div class="box-body">
                <table class="table">
                    <thead>
                    <tr>
                        <th>用户ID</th>
                        <th>用户名</th>
                        <th>身份</th>
                        <th>总收入</th>
                        <th>注册时间</th>
                        <th>最好登录IP</th>
                        <th>状态</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(item,index) in lists">
                        <td>
                            <span v-text="item.id"></span>
                        </td>
                        <td>
                            <span v-text="item.name"></span>
                        </td>
                        <td>
                            <span v-text="identitys[item.identity]"></span>
                        </td>
                        <td>
                            <span v-text="item.id"></span>
                        </td>
                        <td>
                            <span v-text="item.created_at"></span>
                        </td>
                        <td>
                            <span v-text="item.id"></span>
                        </td>
                        <td>
                            <span v-text="item.id"></span>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </section>
@endsection

@section('script')
    <script type="text/javascript">

        require(['Vue', 'VueResource'], function (Vue, VueResource) {
            Vue.use(VueResource)
            var app = new Vue({
                el: '#app',
                data: {
                    identitys: {!!$identity!!},
                    lists: []
                },
                created: function () {
                    console.log(this._data.identity);
                    getUsersLists(this)
                },
                methods: {
                    verify: function (state) {
                        verifyTask(state);
                    }
                }
            })

            // 获取用户列表
            function getUsersLists(_app) {
                _app.$http.get("/admin/user/getLists")
                        .then(function (response) {
                            var json = response.body;
                            console.log(json)
                            _app._data.lists = json.data.lists;
                        })
                        .catch(function (response) {
                            console.log(response)
                        })
            }

            // 审批任务
            function verifyTask(state) {
                var data = {
                    state: state
                }
                app.$http.post("/admin/task/save", data, {headers: header()})
                        .then(function (response) {
                            var json = response.body;
                            alert(json.msg);
                            if (json.state == 1) {
                                window.location.reload();
                            }
                        }).catch(function (response) {
                            console.log(response)
                        })
            }
        })

    </script>
@endsection